/* 
 * Copyright (C) 2012 Martin Řehánek <Martin.Rehanek at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
goog.provide('kramerius.audio.Track');
goog.require('kramerius.audio.AbstractTrack');


/**
 * @constructor 
 * @param {!string} pid Persistent identifier of the track object in Fedora repository.
 * @param {!string} title Name of the track.
 * @param {!string} length Length of the track
 * @param {!string} audioProxyUrl Url of audio proxy.
 * @param {!boolean} hasMp3 if mp3 datastream is available for this track
 * @param {!boolean} hasOgg if ogg datastream is available for this track
 * @param {!boolean} hasWav if wav datastream is available for this track
 */
kramerius.audio.Track = function (pid, title, length, audioProxyUrl, hasMp3, hasOgg, hasWav){
    kramerius.audio.AbstractTrack.call(this, pid, title, length);
    this.audioProxyUrl_ = audioProxyUrl;
    this.urlArray_ = this.buildUrlArray_(hasMp3, hasOgg, hasWav);
};
goog.inherits(kramerius.audio.Track, kramerius.audio.AbstractTrack);


/**
 * @private
 * @param {!string} dsId Name of requested datastream (audio format).
 * @return {string} Link to content of this datastream (through audio proxy)
*/
kramerius.audio.Track.prototype.datastreamUrl_ = function(dsId){
    return this.audioProxyUrl_ + '/' + this.id_ + '/' + dsId;
};


/**
 * @return {Array.<string>}Array of urls in different format usable by soundmanager.
 */
kramerius.audio.Track.prototype.urlArray = function(){
    return this.urlArray_;
};

/** @private **/
kramerius.audio.Track.prototype.buildUrlArray_ = function(hasMp3, hasOgg, hasWav){
//    if (hasMp3 && hasOgg && hasWav){
//        return [
//        this.datastreamUrl_('OGG'),
//        this.datastreamUrl_('WAV'),
//        this.datastreamUrl_('MP3')
//        ];
//    } else if (hasMp3 && hasOgg && !hasWav){
//        return [
//        this.datastreamUrl_('OGG'),
//        this.datastreamUrl_('MP3')
//        
//        ];
//    } else if (hasMp3 && !hasOgg && hasWav){
//        return [
//        this.datastreamUrl_('WAV'),
//        this.datastreamUrl_('MP3')
//        ];
//    } else if (!hasMp3 && hasOgg && hasWav){
//        return [
//        this.datastreamUrl_('OGG'),
//        this.datastreamUrl_('WAV')
//        ];
//    } else if (hasMp3 && !hasOgg && !hasWav){
//        return [this.datastreamUrl_('MP3')];
//    } else if (!hasMp3 && !hasOgg && hasWav){
//        return [this.datastreamUrl_('WAV')];
//    } else if (!hasMp3 && hasOgg && !hasWav){
//        return [this.datastreamUrl_('OGG')];
//    }else{//nothing    
//        return [];
//    }
    //TODO: vratit zpet i ostatni formaty
    return [this.datastreamUrl_('MP3')];
}


